﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;

namespace Skyttespill
{
    public class Kule : MovingObject
    {
        private float vx, vy;
        public SkPanel skytte_panel;

        // Kule objektet
        public Kule(Point shoutgun, float angle, SkPanel sk_panel) 
        {
            diameter = 5;
            skytte_panel = sk_panel;
            double sin = Math.Sin(angle * (Math.PI / 180));
            double cos = Math.Cos(angle * (Math.PI / 180));

            vx = v * (float)cos;
            vy = v * (float)sin;

            x = shoutgun.X;
            y = shoutgun.Y;
            color = new SolidBrush(Color.Black);
        }
        // Bevegelse av kule i løkke
        public override void Move()
        {
            while (Active)
            {
                y -= vy;
                x -= vx;
                
                // Hvis kule treffer panelside, dreper vi tilsvarende tråd
                Size panelSize = skytte_panel.ClientRectangle.Size;
                if (x < 0)
                    Krash();

                if (x + diameter >= panelSize.Width)
                    Krash();

                if (y < 0)
                    Krash();

                if (y + diameter >= panelSize.Height)
                    Krash();

                Thread.Sleep(10);
            }
        }

        public override void tegn(Graphics g)
        {
            g.FillEllipse(color, Rectangle());
        }
    }
}
